package org.example.fallback;

import cn.jbit.pojo.Order;
import feign.hystrix.FallbackFactory;
import org.example.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;


/**
 * @author 张在成
 * 服务调用异常失败时，fallback返回的类
 *
 */
@Component
public class FallbackFailProcess implements FallbackFactory<OrderService> {


    Logger logger=LoggerFactory.getLogger(FallbackFailProcess.class);

    @Override
    public OrderService create(Throwable throwable) {

        return new OrderService() {
            @Override
            public Order selectOrderByOrderId(Integer orderId) throws Exception {
                logger.error("order-service服务的selectProductList方法出现异常，异常信息如下："+throwable);
                return new Order(13,"在成",34.3,12);
            }

            @Override
            public List<Order> getOrderList() {
                logger.error("order-service服务的getOrderList()方法出现异常，异常信息如下："+throwable);
                return Arrays.asList(
                        new Order(18,"张三",34.3,12),
                        new Order(19,"李四",36.2,120),
                        new Order(20,"王麻子",38.7,29));
            }

            @Override
            public List<Order> selOrderListByIds(List<Integer> list) {
                logger.error("order-service服务的getOrderList()方法出现异常，异常信息如下："+throwable);
                return Arrays.asList(
                        new Order(29,"翠花",22.3,32),
                        new Order(30,"二旦",72.2,43),
                        new Order(31,"清远",89.7,89));
            }
        };
    }
}
